#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "config.h"

int main()
{
    int err;
    int s;
    char *buff = "Hello multicast.";
    int buff_len = strlen(buff);
    
    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0)
    {
        perror("socket()");
        exit(1);
    }

    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(MCAST_PORT);
    addr.sin_addr.s_addr = inet_addr(MCAST_ADDR);

    while (1)
    {
        err = sendto(s, buff, buff_len, 0, (struct sockaddr *)&addr, sizeof(addr));
        if (err < 0)
        {
            perror("sendto()");
            close(s);
            exit(1);
        }
        
        sleep(1);       
    }

    close(s);

    return 0;
}